package com.eugeneMa.entity;

import com.eugeneMa.enumEntity.ClassTimePlanTypeEnum;
import com.eugeneMa.enumEntity.DateFormatEnum;
import com.eugeneMa.util.DateUtil;
import com.eugeneMa.util.NumberUtil;

import java.util.Date;

/**
 * 课时表计划
 *
 * @author Eugenema
 * @date 2022/4/1 21:56
 */
public class ClassTimePlan {
    /** 标题，若存在数字，则会转换成“第x节课” */
    private String title;
    /** 时间区间start */
    private Date timeStart;
    /** 时间区间end */
    private Date timeEnd;
    /** 类型对象 */
    private ClassTimePlanTypeEnum typeObject;
    /** 类型名称 */
    private String type;

    public ClassTimePlan() {
    }

    public ClassTimePlan(String title, Date timeStart, Date timeEnd, ClassTimePlanTypeEnum typeObject) {
        this.title = title;
        this.timeStart = timeStart;
        this.timeEnd = timeEnd;
        this.typeObject = typeObject;
        type = typeObject.getValue();
    }

    public String getTitle() {
        //将数字转换为“第x节课”
        if (NumberUtil.isNumber(title)) {
            title = String.format("第%s节课", NumberUtil.intToChineseNum(Integer.parseInt(title)));
        }
        //增加时间
        title += String.format("：%s", DateUtil.dateToString(timeStart, DateFormatEnum.HOURMINUTE));
        //增加结束时间
        if (timeEnd != null) {
            title += String.format(" -- %s", DateUtil.dateToString(timeEnd, DateFormatEnum.HOURMINUTE));
        }
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Date getTimeStart() {
        return timeStart;
    }

    public void setTimeStart(Date timeStart) {
        this.timeStart = timeStart;
    }

    public Date getTimeEnd() {
        return timeEnd;
    }

    public void setTimeEnd(Date timeEnd) {
        this.timeEnd = timeEnd;
    }

    public ClassTimePlanTypeEnum getTypeObject() {
        return typeObject;
    }

    public void setTypeObject(ClassTimePlanTypeEnum typeObject) {
        this.typeObject = typeObject;
        type = typeObject.getValue();
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Override
    public String toString() {
        return "ClassTimePlan{" +
                "title='" + title + '\'' +
                ", timeStart=" + timeStart +
                ", timeEnd=" + timeEnd +
                ", typeObject=" + typeObject +
                ", type='" + type + '\'' +
                '}';
    }
}
